<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>校园综合服务系统</title>
    <head>
        <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
        <script>
            $(document).ready(function(){
                var sto = window.localStorage.getItem("username")
                var data = $.parseJSON(sto) 
                $.get("http://localhost/edu/student/selected", {studentId: data.id}, function(response) {
                    var rs = $.parseJSON(response)
                    if (rs.code != "00000") {
                        alert("获取已选课程数据失败")
                    }
                    $.each(rs.data, function(index, course) {
                        // 创建表格行和各个单元格
                        var row = $("<tr></tr>");
                        row.append("<td>" + course.courseId + "</td>");
                        row.append("<td>" + course.courseName + "</td>");
                        row.append("<td>" + course.teacherRealname + "</td>");
                        row.append("<td>" + course.creditsCount + "</td>");
                        row.append("<td>" + course.sectionCount + "</td>");
                        row.append("<td>" + course.myScore + "</td>");

                        // 创建补考按钮并附加点击事件
                        var rexamButton = $("<input type='button' value='申请补考' />");
                        rexamButton.click(function() {
                            alert('已申请补考，具体补考时间等待学校通知');
                        });

                        // 创建查看课程按钮并附加点击事件
                        var viewCourseButton = $("<input type='button' value='查看课程' />");
                        viewCourseButton.click(function() {
                            $(location).attr("href", "user_courses_info.html?courseId=" + course.courseId + "&studentId=" + data.id)
                        });

                        // 将按钮添加到表格行中
                        var cell = $("<td></td>");
                        cell.append(rexamButton);
                        cell.append(viewCourseButton);
                        row.append(cell);

                        // 将表格行添加到表格中
                        $("#mycourses").append(row);
                    });

                    
                });
            });
        </script>
        </head>
    <style>
        .container {
            text-align: center;
        }
    </style>
</head>
<body>
    
    <a href="#">我的课程</a><br>
    <a href="all_courses.html">选课</a><br>
    <a href="all_blogs.html">校园论坛</a><br>
    <a href="change_pwd.html">修改密码</a><br>
    <div class="container">    
        <table id="mycourses">
            <thead>
              <tr>
                <th>序号</th>
                <th>课程名称</th>
                <th>任课教师</th>
                <th>学分</th>
                <th>课时数</th>
                <th>成绩</th>
                <th>操作</th>
              </tr>
            </thead>
            <tbody>
              
            </tbody>
          </table>
    </div>
    


</body>
</html>